package com.xhwl.data.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.sdata.Organization;
import com.xhwl.common.pojo.cent.sdata.OrganizationVisibility;
import com.xhwl.data.pojo.dto.OrganizationVisibilityDTO;
import com.xhwl.data.pojo.dto.personal.OrganizationConfigVisibleQuery;
import com.xhwl.data.service.IOrganizationService;
import com.xhwl.data.service.IOrganizationVisibilityService;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: luyi
 * @Description: 组织配置
 * @Date: Create in 17:35 2022/4/6
 */
@RestController
public class OrganizationConfigController {


    @Autowired
    private IOrganizationVisibilityService organizationVisibilityService;

    @Autowired
    private IOrganizationService organizationService;

    private static final Logger log = LoggerFactory.getLogger(OrganizationConfigController.class);

    /**
     * 根据组织id 查询部分可见配置信息
     * @param query
     * @return
     */
    @RequestMapping(value = "/organization-config/visi/list")
    public ResultJson list(@RequestBody OrganizationConfigVisibleQuery query){
        if(null == query.getOrgId()){
            return ResultJson.fail("参数错误");
        }
        Organization organization = organizationService.getById(query.getOrgId());
        if(null == organization){
            return ResultJson.fail("组织不存在");
        }
        QueryWrapper<OrganizationVisibility> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("org_id", query.getOrgId());
        return ResultJson.success(organizationVisibilityService.list(queryWrapper));
    }

    /**
     * 部分可见 新增
     * @return
     */
    @RequestMapping(value = "/organization-config/visi/add")
    public ResultJson add(@RequestBody OrganizationVisibilityDTO organizationVisibilityDTO){
        if(null == organizationVisibilityDTO.getOrgId()){
            return ResultJson.fail("参数错误，缺少组织信息");
        }
        organizationVisibilityService.setPartVisible(organizationVisibilityDTO);
        return ResultJson.success();
    }

}
